﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace RuleSet {
    public sealed class PredicateRule<T> : BaseRule, INotifyPropertyChanged {

        private string _LHS;
        /// <summary>
        /// Left hand side
        /// </summary>
        public string LHS {
            get {
                return _LHS;
            }
            set {
                Type classType = typeof(T);
                PropertyInfo[] pi = classType.GetProperties();
                if (pi.Where(x => x.Name == value).Count() == 1) {
                    _LHS = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("LHS"));
                } else {
                    throw new ArgumentOutOfRangeException(value, "Data class does not contain the specified property.");
                }
            }
        }

        private Operators _Operator;
        /// <summary>
        /// Logical operator
        /// </summary>
        public Operators Operator {
            get {
                return _Operator;
            }
            set {
                _Operator = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Operator"));
            }
        }

        private dynamic _RHS;
        /// <summary>
        /// Right hand side
        /// </summary>
        public dynamic RHS {
            get {
                return _RHS;
            }
            set {
                _RHS = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("RHS"));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}